﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;

namespace AxeFrog.Data
{
	[Export, PartCreationPolicy(CreationPolicy.NonShared)]
	public class ConnectionContextProvider
	{
		private readonly Factory _factory;

		[ImportingConstructor]
		public ConnectionContextProvider(Factory factory)
		{
			_factory = factory;
		}

		public ConnectionContext Connect()
		{
			var cc = new ConnectionContext(_factory);
			if(DefaultConnectionStringName != null)
				cc.Specify(DefaultConnectionStringName);
			//var cc = _factory.Create<ConnectionContext>();
			//if(DefaultConnectionStringName != null)
			//    cc.Specify(DefaultConnectionStringName);
			return cc;
		}

		public ConnectionContext Connect(string connectionStringKey)
		{
			return new ConnectionContext(_factory).Specify(connectionStringKey);
			//return _factory.Create<ConnectionContext>().Specify(connectionStringKey);
		}

		public string DefaultConnectionStringName { get; set; }
	}
}
